from django.shortcuts import  render_to_response
from communicator.models import User
from communicator.utils import get_current_user

class AuthValidator(object):

    def process_request(self, request):
        path = request.path
        if path.startswith('/auth') or path.startswith('/login') \
                    or path.startswith('/static') or path.startswith('/feeds'):
            return None
        user_id = request.session.get('user_id', None)
        if user_id is None:
            return render_to_response('main/auth.html')

    def process_exception(self, request, exception):
        print '------------------ERROR-------------------'
        print 'Request: %s' % request.path
        print 'User: %s' % get_current_user(request).get_short_name()
        print 'Exception: %s' % str(exception)
